package com.ruoyi.web.controller.epidemic;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.epidemic.domain.WxCpSysDept;
import com.ruoyi.epidemic.service.IEpidemicControlDeptService;
import com.ruoyi.epidemic.service.IWxCpSysDeptService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 同步过来的部门管理【原始部门】
 */
@Controller
@RequestMapping("/original/dept")
public class OriginalDeptController extends BaseController {

    private String prefix = "epidemic/dept/original";

    @Autowired
    private IEpidemicControlDeptService epidemicControlDeptService;

    @Autowired
    private IWxCpSysDeptService wxCpSysDeptService;

    /**
     * 同步过来的部门【原始数据】
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztreeList = wxCpSysDeptService.selectDeptTree(new WxCpSysDept());
        return ztreeList;
    }

    /**
     * 选择部门树
     *
     * @param deptId 部门ID
     * @param excludeId 排除ID
     */
    @GetMapping(value = { "/selectDeptTree/{deptId}", "/selectDeptTree/{deptId}/{excludeId}" })
    public String selectDeptTree(@PathVariable("deptId") Long deptId, @PathVariable(value = "excludeId", required = false) String excludeId, ModelMap mmap)
    {
        mmap.put("dept", wxCpSysDeptService.selectWxCpSysDeptByDeptId(deptId));
        mmap.put("excludeId", excludeId);
        return prefix + "/tree";
    }

    @RequiresPermissions("original:dept:view")
    @GetMapping()
    public String dept()
    {
        return prefix + "/dept";
    }

    @RequiresPermissions("original:dept:list")
    @PostMapping("/list")
    @ResponseBody
    public List<WxCpSysDept> list(WxCpSysDept dept)
    {
        List<WxCpSysDept> deptList = wxCpSysDeptService.selectWxCpSysDeptList(dept);
        return deptList;
    }


    /**
     * 选择疫情防控部门树
     *
     */
    @GetMapping(value = { "/selectDeptTree/checkBox" })
    public String selectDeptTreeCheckBox(ModelMap mmap)
    {
        return prefix + "/treeCheckBox";
    }

    @PostMapping("/userlist")
    @ResponseBody
    public List<Map<String, Object>> list(String deptId)
    {
        List<Map<String, Object>> mapList = epidemicControlDeptService.getAllWxCpSysUser(deptId);
        return mapList;
    }


}
